/**
 * @(#)ApkConfigController.java 2017年03月1日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.domian.MiguReadConfigBean;
import org.jsbd.boss.service.IMiguReadConfigService;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseMapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/miguReadConfig")
public class MiguReadConfigController{
	
	@Autowired
	private IMiguReadConfigService miguReadConfigService;

	/**
	 * 列表页面
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "listModel")
	public String showMiguReadConfigList(Model model) throws Exception {
		return "/miguReadConfig/miguReadConfigList";
	}

	@RequestMapping(value = "saveMiguReadConfig")
	@ResponseBody
	public Object saveMiguReadConfig(MiguReadConfigBean miguReadConfig){
		miguReadConfigService.saveMiguReadConfig(miguReadConfig);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "updateMiguReadConfig")
	@ResponseBody
	public Object updateMiguReadConfig(MiguReadConfigBean miguReadConfig){
		if (miguReadConfig.getId() == null) {
			return ResponseMapUtils.responseFail("参数缺失，请确认参数再提交");
		}
		
		MiguReadConfigBean condition=new MiguReadConfigBean();
		condition.setId(miguReadConfig.getId());
		MiguReadConfigBean temp=miguReadConfigService.getMiguReadConfig(condition);
		if(temp==null){
			return ResponseMapUtils.responseFail("记录未找到,请重试");
		}
		
		miguReadConfigService.updateMiguReadConfig(miguReadConfig);
		return ResponseMapUtils.responseSuccess();
	}
	
	@RequestMapping(value = "updateMiguReadStatus")
	@ResponseBody
	public Object updateMiguReadStatus(MiguReadConfigBean miguReadConfig){
		if (miguReadConfig.getId() == null||miguReadConfig.getStatus()==null) {
			return ResponseMapUtils.responseFail("参数缺失，请确认参数再提交");
		}
		miguReadConfigService.updateMiguReadStatus(miguReadConfig);
		return ResponseMapUtils.responseSuccess();
	}

	@RequestMapping(value = "getMiguReadConfig")
	@ResponseBody
	public MiguReadConfigBean getMiguReadConfig(MiguReadConfigBean miguReadConfig) throws Exception {
		return miguReadConfigService.getMiguReadConfig(miguReadConfig);
	}

	@RequestMapping(value = "getMiguReadConfigList")
	@ResponseBody
	public List<MiguReadConfigBean> getMiguReadConfigList(MiguReadConfigBean miguReadConfig) throws Exception {
		return miguReadConfigService.getMiguReadConfigList(miguReadConfig);
	}

	@RequestMapping(value = "getMiguReadConfigListPage")
	@ResponseBody
	public Map<String, Object> getMiguReadConfigListPage(DataGridModel page, MiguReadConfigBean miguReadConfig) throws Exception {
		String sname = miguReadConfig.getName();
		if (StringUtils.isNotBlank(sname)) {
			String[] snames = sname.split(" ");
			List<String> keywords = new ArrayList<>();
			for (String keyword : snames) {
				keywords.add(keyword);
			}
			miguReadConfig.setKeywords(keywords);
		}
		return miguReadConfigService.getMiguReadConfigListPage(page, miguReadConfig);
	}
	
	@RequestMapping(value = "deleteMiguReadConfig")
	@ResponseBody
	public Map<String, Object> deleteMiguReadConfig(MiguReadConfigBean miguReadConfig) throws Exception {
		miguReadConfigService.deleteMiguReadConfig(miguReadConfig);
		return ResponseMapUtils.responseSuccess();
	}
	

}
